<template>

<template v-if="user">
  <van-cell title="昵称" is-link to="/user/edit" :value="user.username" @click="toEdit('username','昵称',user.username)" />
  <van-cell title="账号" :value="user.userAccount" @click="showAccountForbid"/>
  <van-cell title="头像" is-link to="/user/edit" >
    <img style="height: 60px;border-radius:50%;" :src="user.avatarUrl" />
  </van-cell>
  <van-cell title="性别" is-link to="/user/edit" :value="user.gender === 0 ? '男' : '女'" @click="toEdit('gender','性别',user.gender)"/>
  <van-cell title="个性签名" is-link to="/user/edit" :value="user.profile" @click="toEdit('profile','个签',user.profile)"/>
  <van-cell title="电话" is-link to="/user/edit" :value="user.phone" @click="toEdit('phone','电话',user.phone)"/>
  <van-cell title="邮箱" is-link to="/user/edit" :value="user.email" @click="toEdit('email','邮箱',user.email)"/>
  <van-cell title="星球编号" :value="user.planetCode" @click="showPlanetCodeForbid"/>
  <van-cell title="注册时间" :value="createTime" @click="showCreateTimeForbid"/>
</template>

</template>


<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user.ts";
import {showFailToast, showToast} from "vant";
import moment from "moment";

// const user = {
//   id: 1,
//   username: '树脂鼠鼠果酱',
//   userAccount: 'Guo Jianghui',
//   avatarUrl: 'src/assets/cuteYuPi.png',
//   gender: '男',
//   phone: '13865837908',
//   email: '1258981151@qq.com',
//   planetCode: '1',
//   createTime: new Date(),
// }

const user = ref();
const router = useRouter();


onMounted(async () => {
  const res = await getCurrentUser();
  if (res){
    user.value = res;
  } else {
    showFailToast('获取用户信息失败')
  }
})

const createTime = moment(user.createTime).format("YYYY-MM-DD");

const toEdit = (editKey: string,editName: string,currentValue: string) => {
  router.push({
    path: '/user/edit',
    query: {
      editKey,
      editName,
      currentValue,
    }
  })
}

const showAccountForbid = () => {
  showFailToast('账号不可修改');
}

const showPlanetCodeForbid = () => {
  showFailToast('星球编号不可修改');
}

const showCreateTimeForbid = () => {
  showFailToast('注册时间不可修改');
}

</script>


<style scoped>

</style>